package com.example.date_selector

import android.app.Activity
import android.os.Build
import android.os.Bundle
import android.widget.DatePicker
import android.widget.Toast
import androidx.annotation.RequiresApi
import java.util.*

//继承自最顶层的Activity，让其没有那个appCompatActivity初始化界面
class MainActivity : Activity() {

    @RequiresApi(Build.VERSION_CODES.O)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val datePicker = findViewById<DatePicker>(R.id.date_picker)
        datePicker.setOnDateChangedListener{ datePicker: DatePicker, year: Int, monthOfYear: Int, dayOfMonth: Int ->
            show(year,monthOfYear,dayOfMonth)
        }
    }

    private fun show(year: Int, month: Int, day: Int) {
        Toast.makeText(this, "今天是：$year/$month/$day",Toast.LENGTH_SHORT).show()
    }
}
